package DP1;

/**
 * 全排列
 */
public class Main16 {
    public static void main(String[] args) {
        int[] arr = {1,2,3};
        perm(arr,0,arr.length-1);
    }

    public static void perm(int[] arr,int p,int q){
        if(p == q){
            show(arr);
        }else{
            for (int i = p; i <= q; i++) {
                swap(arr,p,i);
                perm(arr,p+1,q);
                swap(arr,p,i);
            }
        }
    }

    public static void show(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }



    public static void swap(int[] arr,int i,int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }


}
